﻿using Customer.Domain.Dto;
using Customer.Read.API.Applcation.Command.RefundCommand;
using Customer.Read.API.Applcation.Command.SalesRefundCommand;
using Customer.Read.API.Dtos;
using Customer.Read.API.Server;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Customer.Read.API.Controllers
{
    /// <summary>
    /// 退货控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [Authorize]
    [ApiController]
    public class RefundController : ControllerBase
    {

        IMediator mediator;
        httpshow _http;

        public RefundController(IMediator mediator, httpshow _http)
        {
            this.mediator = mediator;
            this._http = _http;
        }

        /// <summary>
        /// 显示销售退货 
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<Page<RefundListDto>>> GetSalesRefund([FromQuery] RefundShowCommand command)
        {
            ApiResult<Page<RefundListDto>> result = new ApiResult<Page<RefundListDto>>();
            try
            {
                result.Code = 200;
                result.Message = "显示成功";
                result.Data = await mediator.Send(command);
            }
            catch (Exception ee)
            {
                result.Code = -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }


        /// <summary>
        /// 显示销售退货详情
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<RefundListDto>>> GetSalesRefundDetail([FromQuery] RefundDetailCommand command)
        {
            ApiResult<List<RefundListDto>> result = new ApiResult<List<RefundListDto>>();
            try
            {
                result.Code = 200;
                result.Message = "显示成功";
                result.Data = await mediator.Send(command);
            }
            catch (Exception ee)
            {
                result.Code = -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }



    }
}
